﻿using clf.weighing.entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace weighing
{
    public abstract class BaseDao<T> where T : BaseEntity, new()
    {
        public SqliteHelper Sqlite
        {
            get
            {
               return SqliteHelper.Instance;
            }
        }

        public abstract string GetTableName();

        public T? FindById(long id)
        {
            string condition = $"id = {id} ";
            string tableName = GetTableName();
            string sql = SqlBuilder.GetSelectSqlWithSoftDeleteCondition(tableName, null, condition, null, null, null, 1);
            List<T> datas = Sqlite.Select<T>(sql);
            return datas.FirstOrDefault();
        }

        public List<T> SelectAll()
        {
            string table = GetTableName();
            string sql = SqlBuilder.GetSelectSqlWithSoftDeleteCondition(table);
            return Sqlite.Select<T>(sql);
        }

    }
}
